/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.yournamehere.guice;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
import com.google.inject.matcher.Matchers;
import com.wideplay.warp.persist.PersistenceService;
import com.wideplay.warp.persist.TransactionStrategy;
import com.wideplay.warp.persist.UnitOfWork;

/**
 *
 * @author odpsoft
 */
public class ModuleFactory {

    private static ModuleFactory factory;

    synchronized public static ModuleFactory getInstance() {
        if (factory == null) {
            factory = new ModuleFactory();
        }

        return factory;
    }
    private Injector hibernateInjector;

    private ModuleFactory() {
        hibernateInjector = Guice.createInjector(Stage.DEVELOPMENT, new MyModule(), PersistenceService.usingHibernate().
                across(UnitOfWork.TRANSACTION).addAccessor(PersonAccess.class).
                transactedWith(TransactionStrategy.LOCAL).
                forAll(Matchers.any()).
                buildModule());
        
        hibernateInjector.getInstance(PersistenceService.class).start();
    }

    public <T> T getInstance(Class<T> type) {
        return hibernateInjector.getInstance(type);
    }
}
